<?php

class Lib {

    public static function isset_or(&$var, $default = NULL) {
            return isset($var) ? $var : $default;
    }

    public static function set_default(&$var, $default = NULL) {
            return $var = self::isset_or($var, $default);
    }

	public static function log($object) {
		FirePhp::getInstance(true)->log($object);
	}
	
	public static function recountProducts() {
		$productRowset = ProductPeer::getInstance()->fetchAll();
		
		$products = array();
		
		foreach ($productRowset as $productRow) {
			$parentId = $productRow->getParentId();
			self::set_default($products[$parentId], 0);
			$products[$parentId]++;
		}
		
		foreach ($productRowset as $productRow) {
			$id = $productRow->getId();
			$productRow->setSubproductsCount($products[$id]);
			$productRow->save();
		}
	}
}

?>
